<?php
// $Id: FrontController.php 602 2012-12-14 07:47:38Z tomqin@gmail.com $

/**
 * Part of the framework.
 *
 * @package     Controller
 * @version     1.0
 * @copyright   Copyright (C) 2010-2012 SupeFun.com Inc.
 * @author      TomQin <tomqin@gmail.com>
 * @license     http://www.supefun.com/license/
 */

class Validate
{
    //判断电子邮件
    static public function isEmail($email) {
        if (strpos($email, '@') !== false && strpos($email, '.') !== false) {
            $chars = "/^([a-z0-9+_]|\-|\.)+@(([a-z0-9_]|\-)+\.)+[a-z]{2,6}\$/i";
            if (preg_match($chars, $email)) {
                return true;
            }else {
                return false;
            }
        } else {
            return false;
        }
    }

    //判断数字
    static public function isNumber($number, $len = 0) {
        if($len)
            return preg_match("/^\d+$/", $number);
        else
            return preg_match("/^\d{$len}$/", $number);
    }

    //判断手机号码(中国大陆)
    static public function isMobile($mobile) {
        if (preg_match("/^1[3589]\d{9}$/", $mobile)) {
            return true;
        }else{
            return false;
        }
    }

    //判断是否为中文字符
    static public function isChinese($str) {
        //if(preg_match('/^([\x81-\xfe][\x40-\xfe]) {0,2}$/',$str)) {
        //if(preg_match("/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_]+$/",$str)) //GB2312汉字字母数字下划线正则表达式
        if(preg_match("/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u", $str)) {   //UTF-8汉字字母数字下划线正则表达式
            return true;
        }else{
            return false;
        }
    }

    //身份证号码
    static public function isIdCard($idcard) {
    }


    static public function isTelphone($telphone) {
        $chars = "/^(\d{3,4}\-?)?\d{5,}$/";

        if (preg_match($chars, $telphone)) {
            return true;
        }else{
            return false;
        }
    }



    function is_url($user_url)
{
    $chars = "/((^http)|(^https)|(^ftp)):\/\/(\S)+\.(\w)+/";

    if (preg_match($chars, $user_url))
    {
        return true;
    }else
    {
        return false;
    }
}
}
